// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SRM_S03 : AbstractMessage
    {
		/// Constructor
		public SRM_S03() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "SRM", TriggerEvent = "S03" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ARQ",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v231, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v25, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.False, HL7Required.True,"ARQ")]
	    public ARQ ARQ {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("APR",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v231, 4, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v24, 4, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v25, 3, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.False, HL7Required.False,"APR")]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.False, HL7Required.False,"APR")]
	    public APR APR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NTE",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v231, 8, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v24, 8, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v25, 4, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATIENT",11)]
  	    [HL7Field(HL7Version.v23, 11, HL7Repeat.False, HL7Required.False,"PATIENT_SRM_S03")]
  	    [HL7Field(HL7Version.v231, 11, HL7Repeat.False, HL7Required.False,"PATIENT_SRM_S01")]
  	    [HL7Field(HL7Version.v24, 11, HL7Repeat.False, HL7Required.False,"PATIENT_SRM_S01")]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.True, HL7Required.False,"PATIENT_SRM_S01")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.True, HL7Required.False,"PATIENT_SRM_S01")]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.True, HL7Required.False,"PATIENT_SRM_S01")]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.True, HL7Required.False,"PATIENT_SRM_S01")]
	    public PATIENT_SRM_S03[] PATIENT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RESOURCES",32)]
  	    [HL7Field(HL7Version.v23, 32, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S03")]
  	    [HL7Field(HL7Version.v231, 32, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
  	    [HL7Field(HL7Version.v24, 32, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
  	    [HL7Field(HL7Version.v25, 13, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
  	    [HL7Field(HL7Version.v251, 12, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
  	    [HL7Field(HL7Version.v26, 13, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
  	    [HL7Field(HL7Version.v27, 12, HL7Repeat.True, HL7Required.True,"RESOURCES_SRM_S01")]
	    public RESOURCES_SRM_S03[] RESOURCES {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("GENERAL_RESOURCE",47)]
  	    [HL7Field(HL7Version.v23, 47, HL7Repeat.False, HL7Required.False,"GENERAL_RESOURCE_SRM_S03")]
  	    [HL7Field(HL7Version.v231, 47, HL7Repeat.False, HL7Required.False,"GENERAL_RESOURCE_SRM_S01")]
  	    [HL7Field(HL7Version.v24, 47, HL7Repeat.False, HL7Required.False,"GENERAL_RESOURCE_SRM_S01")]
	    public GENERAL_RESOURCE_SRM_S03 GENERAL_RESOURCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("LOCATION_RESOURCE",60)]
  	    [HL7Field(HL7Version.v23, 60, HL7Repeat.False, HL7Required.False,"LOCATION_RESOURCE_SRM_S03")]
  	    [HL7Field(HL7Version.v231, 60, HL7Repeat.False, HL7Required.False,"LOCATION_RESOURCE_SRM_S01")]
  	    [HL7Field(HL7Version.v24, 60, HL7Repeat.False, HL7Required.False,"LOCATION_RESOURCE_SRM_S01")]
	    public LOCATION_RESOURCE_SRM_S03 LOCATION_RESOURCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PERSONNEL_RESOURCE",73)]
  	    [HL7Field(HL7Version.v23, 73, HL7Repeat.False, HL7Required.False,"PERSONNEL_RESOURCE_SRM_S03")]
  	    [HL7Field(HL7Version.v231, 73, HL7Repeat.False, HL7Required.False,"PERSONNEL_RESOURCE_SRM_S01")]
  	    [HL7Field(HL7Version.v24, 73, HL7Repeat.False, HL7Required.False,"PERSONNEL_RESOURCE_SRM_S01")]
	    public PERSONNEL_RESOURCE_SRM_S03 PERSONNEL_RESOURCE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		 GENERAL_RESOURCE = ProcessGroup<GENERAL_RESOURCE_SRM_S03>(availableData, options, "GENERAL_RESOURCE");
		 LOCATION_RESOURCE = ProcessGroup<LOCATION_RESOURCE_SRM_S03>(availableData, options, "LOCATION_RESOURCE");
		 PERSONNEL_RESOURCE = ProcessGroup<PERSONNEL_RESOURCE_SRM_S03>(availableData, options, "PERSONNEL_RESOURCE");
		}
		if (HL7Version.v231 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		 GENERAL_RESOURCE = ProcessGroup<GENERAL_RESOURCE_SRM_S03>(availableData, options, "GENERAL_RESOURCE");
		 LOCATION_RESOURCE = ProcessGroup<LOCATION_RESOURCE_SRM_S03>(availableData, options, "LOCATION_RESOURCE");
		 PERSONNEL_RESOURCE = ProcessGroup<PERSONNEL_RESOURCE_SRM_S03>(availableData, options, "PERSONNEL_RESOURCE");
		}
		if (HL7Version.v24 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		 GENERAL_RESOURCE = ProcessGroup<GENERAL_RESOURCE_SRM_S03>(availableData, options, "GENERAL_RESOURCE");
		 LOCATION_RESOURCE = ProcessGroup<LOCATION_RESOURCE_SRM_S03>(availableData, options, "LOCATION_RESOURCE");
		 PERSONNEL_RESOURCE = ProcessGroup<PERSONNEL_RESOURCE_SRM_S03>(availableData, options, "PERSONNEL_RESOURCE");
		}
		if (HL7Version.v25 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		}
		if (HL7Version.v251 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		}
		if (HL7Version.v26 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		}
		if (HL7Version.v27 == options.Version) {
		 ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
		 APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 PATIENT = ProcessGroupArray<PATIENT_SRM_S03>(availableData, options, "PATIENT");
		 RESOURCES = ProcessGroupArray<RESOURCES_SRM_S03>(availableData, options, "RESOURCES");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SRM_S03";
			}
        }

        static SRM_S03() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SRM_S03));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (ARQ != null) {
				segmentData.Add(ARQ.GetER7(options));
			}
			if (APR != null) {
				segmentData.Add(APR.GetER7(options));
			}
			if (NTE != null && NTE.Length > 0) {
				for (int i = 0; i < NTE.Length; i++) {
					segmentData.Add(NTE[i].GetER7(options));
				}
			}
			if (PATIENT != null && PATIENT.Length > 0) {
				for (int i = 0; i < PATIENT.Length; i++) {
					segmentData.Add(PATIENT[i].GetER7(options));
				}
			}
			if (RESOURCES != null && RESOURCES.Length > 0) {
				for (int i = 0; i < RESOURCES.Length; i++) {
					segmentData.Add(RESOURCES[i].GetER7(options));
				}
			}
			if (GENERAL_RESOURCE != null) {
				segmentData.Add(GENERAL_RESOURCE.GetER7(options));
			}
			if (LOCATION_RESOURCE != null) {
				segmentData.Add(LOCATION_RESOURCE.GetER7(options));
			}
			if (PERSONNEL_RESOURCE != null) {
				segmentData.Add(PERSONNEL_RESOURCE.GetER7(options));
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

